package com.xiaofeng.pochi.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xiaofeng.pochi.common.Page;
import com.xiaofeng.pochi.enums.StateEnums;
import com.xiaofeng.pochi.mapper.SysNoticeMapper;
import com.xiaofeng.pochi.mapper.SysRoleMapper;
import com.xiaofeng.pochi.pojo.SysNotice;
import com.xiaofeng.pochi.pojo.SysRole;
import com.xiaofeng.pochi.pojo.vo.SysUserVo;
import com.xiaofeng.pochi.service.SysNoticeService;
import com.xiaofeng.pochi.service.SysRoleService;
import com.xiaofeng.pochi.utils.ShiroUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created with IntelliJ IDEA
 *
 * @Author: chc
 * @Date: 2022/08/07/20:59
 * @Description:
 */
@Service
public class SysNoticeServiceImpl extends ServiceImpl<SysNoticeMapper, SysNotice> implements SysNoticeService {
    @Autowired
    private SysNoticeMapper sysNoticeMapper;

    @Override
    public void update(SysNotice sysNotice) {
        sysNoticeMapper.update(sysNotice);
    }

    @Override
    public SysNotice get(Long id) {
        return sysNoticeMapper.get(id);
    }

    @Override
    public void delete(Long id) {
        sysNoticeMapper.delete(id);
    }

    @Override
    public void enable(Long id) {
        SysNotice sysNotice = sysNoticeMapper.get(id);
        sysNotice.setEnabled(StateEnums.ENABLED.getCode());
        sysNoticeMapper.updateEnable(sysNotice);
    }

    @Override
    public void disable(Long id) {
        SysNotice sysNotice = sysNoticeMapper.get(id);
        sysNotice.setEnabled(StateEnums.NOT_ENABLE.getCode());
        sysNoticeMapper.updateEnable(sysNotice);
    }

    @Override
    public Page<SysNotice> getByPage(Page<SysNotice> page) {
        List<SysNotice> list = sysNoticeMapper.getByPage(page);
        Integer totalCount = sysNoticeMapper.countByPage(page);
        page.setList(list);
        page.setTotalCount(totalCount);
        return page;
    }

    @Override
    public List<SysNotice> getNoticeList() {
        return sysNoticeMapper.getNoticeList();
    }
}
